﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class GameMgr : MonoBehaviour {
    public static GameMgr s_Instance;
    public Transform m_Content;
    public Block m_BlockPrefab;
    public int m_RowCount, m_ColumnCount;
    public MoveObj.ObjType m_ObjTypeNow;
    public int m_ObjStateNow;
    public Text m_ScoreText,m_LevelText,m_ScoreCountText,m_PauseText;
    public Slider m_LevelSlider,m_CountSlider;
    public Text m_CountText;
    public List<Block> m_AllBlockList = new List<Block>();
    public List<Block> m_MovingBlcokList = new List<Block>();
    public float m_LevelFact;
    public List<GameObject> m_ButtonObjList = new List<GameObject>();
    public GameObject m_EndGameObj;
    private float m_timer,m_escapeTimer1,m_escapeTimer2;
    private int m_score;
    private int m_hardScore;
    [SerializeField]
    private int m_count;
    private bool m_isStarted,m_isEnd,m_isPaused;
    private System.Action m_updateAction;
	// Use this for initialization
	void Awake () {
        s_Instance = this;
    }
    private void Start() {
        for(int i = 0; i < m_RowCount; i++) {
            for(int j = 0; j < m_ColumnCount; j++) {
                Block obj = Instantiate(m_BlockPrefab) as Block;
                obj.transform.SetParent(m_Content);
                obj.transform.localScale = new Vector3(1f,1f,1f);
                obj.m_Row = i;
                obj.m_Column = j;
                m_AllBlockList.Add(obj);
            }
        }
    }
    void Update() {
        if (Input.GetKeyDown(KeyCode.A)) {
            InitNewOne();
        }
        if (Input.GetKeyDown(KeyCode.LeftArrow)) {
            MovingTranslation(-1);
        }
        if (Input.GetKeyDown(KeyCode.RightArrow)) {
            MovingTranslation(1);
        }
        if (Input.GetKey(KeyCode.DownArrow)) {
            MovingFall(1);
        }
        if (Input.GetKeyDown(KeyCode.UpArrow)) {
            MovingRotate();
        }
        if (Input.GetKeyDown(KeyCode.Escape)) {
            m_escapeTimer2 = Time.realtimeSinceStartup;
            if (m_escapeTimer2 - m_escapeTimer1 < 0.3f) {
                print("Quit");
                Application.Quit();
            }
            m_escapeTimer1 = m_escapeTimer2;
        }

        m_LevelFact = m_LevelSlider.value;
        m_LevelText.text = m_LevelFact.ToString("#0.00");
        m_count = (int)m_CountSlider.value;
        m_CountText.text = m_count.ToString();
        if (m_updateAction != null) {
            m_updateAction();
        }
       
    }
    void updateFall() {
        if (m_timer < 10f) {
            m_timer += Time.deltaTime*m_LevelFact;
        } else {
            MovingFall(1);
            m_timer = 0;
        }
    }
    void InitNewOne() {
        m_MovingBlcokList.Clear();
        InitOne(NextObj.s_Instance.m_MoveObjNow.m_PosList, NextObj.s_Instance.m_MoveObjNow.m_ObjType);
        m_ObjTypeNow = NextObj.s_Instance.m_MoveObjNow.m_ObjType;
        NextObj.s_Instance.FreshOneMoveObj();
        m_ObjStateNow = 0;
    }
    public void InitOne(List<Vector2> poslist,MoveObj.ObjType type) {
        foreach(var item in poslist) {
            int x = 0;
            if (item.x > 0) {
                x = 10;
            }
            if (!m_AllBlockList[3+x + (int)item.y].m_IsHighLight) {
                m_AllBlockList[3+x + (int)item.y].HighLight(type);
                m_AllBlockList[3 + x + (int)item.y].m_IsMoving = true;
                m_MovingBlcokList.Add(m_AllBlockList[3 + x + (int)item.y]);
            } else {
                Debug.LogWarning("ENDDDDDDDDDD");
                m_EndGameObj.SetActive(true);
                foreach(var item1 in m_ButtonObjList) {
                    item1.SetActive(false);
                }
            }
        }
    }
    public void HighLightByPos(int row,int column,MoveObj.ObjType type) {
        m_AllBlockList[row * m_ColumnCount + column].HighLight(type);
    }
    public void DeLightByPos(int row, int column) {
        m_AllBlockList[row * m_ColumnCount + column].DeLight();
    }
    public void MovingFall(int fallcount) {
        if (m_MovingBlcokList.Count <= 0 || m_isPaused) {
            return;
        }
        if (CheckVerticalEnable(m_MovingBlcokList, fallcount)) {
            MoveObj.ObjType type = MoveObj.ObjType.Init;
            type = m_MovingBlcokList[0].m_ObjType;
            foreach (var item in m_MovingBlcokList) {
                m_AllBlockList[item.m_Row * m_ColumnCount + item.m_Column].Fall1(fallcount);
            }
            foreach (var item in m_MovingBlcokList) {
                m_AllBlockList[item.m_Row * m_ColumnCount + item.m_Column].Fall2(fallcount, type);
            }
            for (int i = 0; i < m_MovingBlcokList.Count; i++) {
                int r = m_MovingBlcokList[i].m_Row + 1;
                int c = m_MovingBlcokList[i].m_Column;
                m_MovingBlcokList[i] = m_AllBlockList[r * m_ColumnCount + c];
                m_MovingBlcokList[i].m_IsMoving = true;
            }
        } else {
            foreach (var item in m_MovingBlcokList) {
                foreach (var item1 in m_MovingBlcokList) {
                    item1.m_IsMoving = false;
                }
            }
            CheckFull();
            
        }
    }
    void CheckFull() {
        for(int row = m_RowCount-1; row >=0; row--) {
            bool flag = true;
            for(int column = 0; column < m_ColumnCount; column++) {
                if (!m_AllBlockList[row * m_ColumnCount + column].m_IsHighLight) {
                    flag = false;
                }
            }
            if (flag) {
                
                m_score++;
                m_hardScore++;
                m_ScoreCountText.text = m_score.ToString();
                float x = (m_LevelFact / 20f + 1f);
                float y = (20 - m_count) / 20f *5f;
                m_ScoreText.text = (m_score*x+y).ToString("#0.0");
                for (int i = row; i > 0; i--) {
                    for(int j = 0; j < m_ColumnCount; j++) {
                        if (m_AllBlockList[(i-1) * m_ColumnCount + j].m_IsHighLight) {
                            m_AllBlockList[i * m_ColumnCount + j].HighLight(m_AllBlockList[i * m_ColumnCount + j].m_ObjType);
                        } else {
                            m_AllBlockList[i * m_ColumnCount + j].DeLight();
                        }
                    }
                }
                for (int i = 0; i < m_ColumnCount; i++) {
                    m_AllBlockList[m_ColumnCount + i].DeLight();
                }
                if (m_hardScore >= m_count) {
                    m_hardScore = 0;
                    for (int i = 0; i < m_RowCount - 1; i++) {
                        for (int j = 0; j < m_ColumnCount; j++) {
                            if (m_AllBlockList[(i + 1) * m_ColumnCount + j].m_IsHighLight) {
                                m_AllBlockList[i * m_ColumnCount + j].HighLight(m_AllBlockList[(i+1) * m_ColumnCount + j].m_ObjType);
                            } else {
                                m_AllBlockList[i * m_ColumnCount + j].DeLight();
                            }
                        }
                    }
                    for (int i = 0; i < m_ColumnCount; i++) {
                        m_AllBlockList[(m_RowCount - 1) * m_ColumnCount + i].DeLight();
                    }
                    int count = Random.Range(3, 8);
                    List<int> list = new List<int>();
                    for (int i = 0; i < m_ColumnCount; i++) {
                        list.Add(i);
                    }
                    for (int i = 0; i < m_ColumnCount - count; i++) {
                        int a = Random.Range(0, m_ColumnCount);
                        list.Remove(a);
                    }
                    foreach (var item in list) {
                        m_AllBlockList[(m_RowCount - 1) * m_ColumnCount + item].HighLight(MoveObj.ObjType.Black);
                    }
                }
                row = m_RowCount;
            }
        }
        InitNewOne();
    }
    public void MovingTranslation(int horizencount) {
        if (m_MovingBlcokList.Count <= 0 || m_isPaused) {
            return;
        }
        if (GameMgr.s_Instance.CheckHorizenEnable(m_MovingBlcokList, horizencount)) {
            MoveObj.ObjType type = MoveObj.ObjType.Init;
            type = m_MovingBlcokList[0].m_ObjType;
            foreach (var item in m_MovingBlcokList) {
                GameMgr.s_Instance.m_AllBlockList[item.m_Row * GameMgr.s_Instance.m_ColumnCount + item.m_Column].Translation1(horizencount);
            }
            foreach (var item in m_MovingBlcokList) {
                GameMgr.s_Instance.m_AllBlockList[item.m_Row * GameMgr.s_Instance.m_ColumnCount + item.m_Column].Translation2(horizencount, type);
            }
            for (int i = 0; i < m_MovingBlcokList.Count; i++) {
                int r = m_MovingBlcokList[i].m_Row ;
                int c = m_MovingBlcokList[i].m_Column+ horizencount;
                m_MovingBlcokList[i] = m_AllBlockList[r * m_ColumnCount + c];
                m_MovingBlcokList[i].m_IsMoving = true;
            }
        }
    }
    public void MovingRotate() {
        if (m_MovingBlcokList.Count <= 0||m_isPaused) {
            return;
        }
        int x1, x2, x3, x4;
        int y1, y2, y3, y4;
        switch (m_ObjTypeNow) {
            case MoveObj.ObjType.White:
                
                if(m_ObjStateNow == 0) {
                    x1 = m_MovingBlcokList[2].m_Row-2;
                    y1 = m_MovingBlcokList[2].m_Column;
                    x2 = m_MovingBlcokList[2].m_Row - 1;
                    y2 = m_MovingBlcokList[2].m_Column;
                    x3 = m_MovingBlcokList[2].m_Row;
                    y3 = m_MovingBlcokList[2].m_Column;
                    x4 = m_MovingBlcokList[2].m_Row +1;
                    y4 = m_MovingBlcokList[2].m_Column;
                    if(setRotate(x1, y1, x2, y2, x3, y3, x4, y4)) {
                        m_ObjStateNow = 1;
                    }
                    
                    
                    break;
                }
                if (m_ObjStateNow == 1) {
                    x1 = m_MovingBlcokList[2].m_Row;
                    y1 = m_MovingBlcokList[2].m_Column-2;
                    x2 = m_MovingBlcokList[2].m_Row;
                    y2 = m_MovingBlcokList[2].m_Column-1;
                    x3 = m_MovingBlcokList[2].m_Row;
                    y3 = m_MovingBlcokList[2].m_Column;
                    x4 = m_MovingBlcokList[2].m_Row;
                    y4 = m_MovingBlcokList[2].m_Column+1;
                    if (setRotate(x1, y1, x2, y2, x3, y3, x4, y4)) {
                        m_ObjStateNow = 0;
                    }
                    break;
                }
                break;
            case MoveObj.ObjType.Blue:
                if (m_ObjStateNow == 0) {
                    x1 = m_MovingBlcokList[0].m_Row;
                    y1 = m_MovingBlcokList[0].m_Column+1;
                    x2 = m_MovingBlcokList[0].m_Row;
                    y2 = m_MovingBlcokList[0].m_Column;
                    x3 = m_MovingBlcokList[0].m_Row+1;
                    y3 = m_MovingBlcokList[0].m_Column;
                    x4 = m_MovingBlcokList[0].m_Row + 2;
                    y4 = m_MovingBlcokList[0].m_Column;
                    if (setRotate(x1, y1, x2, y2, x3, y3, x4, y4)) {
                        m_ObjStateNow = 1;
                    }
                    break;
                }
                if (m_ObjStateNow == 1) {
                    x1 = m_MovingBlcokList[0].m_Row+1;
                    y1 = m_MovingBlcokList[0].m_Column;
                    x2 = m_MovingBlcokList[0].m_Row;
                    y2 = m_MovingBlcokList[0].m_Column;
                    x3 = m_MovingBlcokList[0].m_Row ;
                    y3 = m_MovingBlcokList[0].m_Column -1;
                    x4 = m_MovingBlcokList[0].m_Row ;
                    y4 = m_MovingBlcokList[0].m_Column -2;
                    if (setRotate(x1, y1, x2, y2, x3, y3, x4, y4)) {
                        m_ObjStateNow = 2;
                    }
                    break;
                }
                if (m_ObjStateNow == 2) {
                    x1 = m_MovingBlcokList[0].m_Row;
                    y1 = m_MovingBlcokList[0].m_Column - 1;
                    x2 = m_MovingBlcokList[0].m_Row;
                    y2 = m_MovingBlcokList[0].m_Column;
                    x3 = m_MovingBlcokList[0].m_Row-1;
                    y3 = m_MovingBlcokList[0].m_Column;
                    x4 = m_MovingBlcokList[0].m_Row -2;
                    y4 = m_MovingBlcokList[0].m_Column;
                    if (setRotate(x1, y1, x2, y2, x3, y3, x4, y4)) {
                        m_ObjStateNow = 3;
                    }
                    break;
                }
                if (m_ObjStateNow == 3) {
                    x1 = m_MovingBlcokList[0].m_Row-1;
                    y1 = m_MovingBlcokList[0].m_Column ;
                    x2 = m_MovingBlcokList[0].m_Row;
                    y2 = m_MovingBlcokList[0].m_Column;
                    x3 = m_MovingBlcokList[0].m_Row;
                    y3 = m_MovingBlcokList[0].m_Column+1;
                    x4 = m_MovingBlcokList[0].m_Row ;
                    y4 = m_MovingBlcokList[0].m_Column+2;
                    if (setRotate(x1, y1, x2, y2, x3, y3, x4, y4)) {
                        m_ObjStateNow = 0;
                    }
                    break;
                }
                break;

            case MoveObj.ObjType.Orange: 
                if (m_ObjStateNow == 0) {
                    x1 = m_MovingBlcokList[0].m_Row-2;
                    y1 = m_MovingBlcokList[0].m_Column + 1;
                    x2 = m_MovingBlcokList[0].m_Row-1;
                    y2 = m_MovingBlcokList[0].m_Column+1;
                    x3 = m_MovingBlcokList[0].m_Row ;
                    y3 = m_MovingBlcokList[0].m_Column+1;
                    x4 = m_MovingBlcokList[0].m_Row;
                    y4 = m_MovingBlcokList[0].m_Column+2;
                    if (setRotate(x1, y1, x2, y2, x3, y3, x4, y4)) {
                        m_ObjStateNow = 1;
                    }
                    break;
                }
                if (m_ObjStateNow == 1) {
                    x1 = m_MovingBlcokList[0].m_Row + 1;
                    y1 = m_MovingBlcokList[0].m_Column+2;
                    x2 = m_MovingBlcokList[0].m_Row+1;
                    y2 = m_MovingBlcokList[0].m_Column+1;
                    x3 = m_MovingBlcokList[0].m_Row+1;
                    y3 = m_MovingBlcokList[0].m_Column;
                    x4 = m_MovingBlcokList[0].m_Row+2;
                    y4 = m_MovingBlcokList[0].m_Column;
                    if (setRotate(x1, y1, x2, y2, x3, y3, x4, y4)) {
                        m_ObjStateNow = 2;
                    }
                    break;
                }
                if (m_ObjStateNow == 2) {
                    x1 = m_MovingBlcokList[0].m_Row+2;
                    y1 = m_MovingBlcokList[0].m_Column - 1;
                    x2 = m_MovingBlcokList[0].m_Row+1;
                    y2 = m_MovingBlcokList[0].m_Column-1;
                    x3 = m_MovingBlcokList[0].m_Row;
                    y3 = m_MovingBlcokList[0].m_Column-1;
                    x4 = m_MovingBlcokList[0].m_Row;
                    y4 = m_MovingBlcokList[0].m_Column-2;
                    if (setRotate(x1, y1, x2, y2, x3, y3, x4, y4)) {
                        m_ObjStateNow = 3;
                    }
                    break;
                }
                if (m_ObjStateNow == 3) {
                    x1 = m_MovingBlcokList[0].m_Row - 1;
                    y1 = m_MovingBlcokList[0].m_Column-2;
                    x2 = m_MovingBlcokList[0].m_Row-1;
                    y2 = m_MovingBlcokList[0].m_Column-1;
                    x3 = m_MovingBlcokList[0].m_Row-1;
                    y3 = m_MovingBlcokList[0].m_Column;
                    x4 = m_MovingBlcokList[0].m_Row-2;
                    y4 = m_MovingBlcokList[0].m_Column;
                    if(setRotate(x1, y1, x2, y2, x3, y3, x4, y4)) {
                        m_ObjStateNow = 0;
                    }
                    break;
                }
                break;
            case MoveObj.ObjType.Green:

                if (m_ObjStateNow == 0) {
                    x1 = m_MovingBlcokList[0].m_Row - 1;
                    y1 = m_MovingBlcokList[0].m_Column+1;
                    x2 = m_MovingBlcokList[0].m_Row;
                    y2 = m_MovingBlcokList[0].m_Column+1;
                    x3 = m_MovingBlcokList[0].m_Row;
                    y3 = m_MovingBlcokList[0].m_Column+2;
                    x4 = m_MovingBlcokList[0].m_Row + 1;
                    y4 = m_MovingBlcokList[0].m_Column+2;
                    if (setRotate(x1, y1, x2, y2, x3, y3, x4, y4)) {
                        m_ObjStateNow = 1;
                    }
                    break;
                }
                if (m_ObjStateNow == 1) {
                    x1 = m_MovingBlcokList[0].m_Row+2;
                    y1 = m_MovingBlcokList[0].m_Column -1;
                    x2 = m_MovingBlcokList[0].m_Row+2;
                    y2 = m_MovingBlcokList[0].m_Column;
                    x3 = m_MovingBlcokList[0].m_Row+1;
                    y3 = m_MovingBlcokList[0].m_Column;
                    x4 = m_MovingBlcokList[0].m_Row+1;
                    y4 = m_MovingBlcokList[0].m_Column + 1;
                    if (setRotate(x1, y1, x2, y2, x3, y3, x4, y4)) {
                        m_ObjStateNow = 0;
                    }
                    break;
                }
                break;
            case MoveObj.ObjType.Red:

                if (m_ObjStateNow == 0) {
                    x1 = m_MovingBlcokList[0].m_Row - 1;
                    y1 = m_MovingBlcokList[0].m_Column + 2;
                    x2 = m_MovingBlcokList[0].m_Row;
                    y2 = m_MovingBlcokList[0].m_Column + 2;
                    x3 = m_MovingBlcokList[0].m_Row;
                    y3 = m_MovingBlcokList[0].m_Column + 1;
                    x4 = m_MovingBlcokList[0].m_Row + 1;
                    y4 = m_MovingBlcokList[0].m_Column + 1;
                    if (setRotate(x1, y1, x2, y2, x3, y3, x4, y4)) {
                        m_ObjStateNow = 1;
                    }
                    break;
                }
                if (m_ObjStateNow == 1) {
                    x1 = m_MovingBlcokList[0].m_Row +1;
                    y1 = m_MovingBlcokList[0].m_Column - 2;
                    x2 = m_MovingBlcokList[0].m_Row+1 ;
                    y2 = m_MovingBlcokList[0].m_Column-1;
                    x3 = m_MovingBlcokList[0].m_Row + 2;
                    y3 = m_MovingBlcokList[0].m_Column-1;
                    x4 = m_MovingBlcokList[0].m_Row + 2;
                    y4 = m_MovingBlcokList[0].m_Column ;
                    if (setRotate(x1, y1, x2, y2, x3, y3, x4, y4)) {
                        m_ObjStateNow = 0;
                    }
                    break;
                }
                break;
            case MoveObj.ObjType.Purple:
                if (m_ObjStateNow == 0) {
                    x1 = m_MovingBlcokList[0].m_Row - 1;
                    y1 = m_MovingBlcokList[0].m_Column + 1;
                    x2 = m_MovingBlcokList[0].m_Row ;
                    y2 = m_MovingBlcokList[0].m_Column + 1;
                    x3 = m_MovingBlcokList[0].m_Row;
                    y3 = m_MovingBlcokList[0].m_Column + 2;
                    x4 = m_MovingBlcokList[0].m_Row+1;
                    y4 = m_MovingBlcokList[0].m_Column + 1;
                    if (setRotate(x1, y1, x2, y2, x3, y3, x4, y4)) {
                        m_ObjStateNow = 1;
                    }
                    break;
                }
                if (m_ObjStateNow == 1) {
                    x1 = m_MovingBlcokList[0].m_Row ;
                    y1 = m_MovingBlcokList[0].m_Column + 1;
                    x2 = m_MovingBlcokList[0].m_Row ;
                    y2 = m_MovingBlcokList[0].m_Column ;
                    x3 = m_MovingBlcokList[0].m_Row + 1;
                    y3 = m_MovingBlcokList[0].m_Column;
                    x4 = m_MovingBlcokList[0].m_Row ;
                    y4 = m_MovingBlcokList[0].m_Column-1;
                    if (setRotate(x1, y1, x2, y2, x3, y3, x4, y4)) {
                        m_ObjStateNow = 2;
                    }
                    break;
                }
                if (m_ObjStateNow == 2) {
                    x1 = m_MovingBlcokList[0].m_Row + 2;
                    y1 = m_MovingBlcokList[0].m_Column - 1;
                    x2 = m_MovingBlcokList[0].m_Row + 1;
                    y2 = m_MovingBlcokList[0].m_Column - 1;
                    x3 = m_MovingBlcokList[0].m_Row+1;
                    y3 = m_MovingBlcokList[0].m_Column - 2;
                    x4 = m_MovingBlcokList[0].m_Row;
                    y4 = m_MovingBlcokList[0].m_Column - 1;
                    if (setRotate(x1, y1, x2, y2, x3, y3, x4, y4)) {
                        m_ObjStateNow = 3;
                    }
                    break;
                }
                if (m_ObjStateNow == 3) {
                    x1 = m_MovingBlcokList[0].m_Row - 1;
                    y1 = m_MovingBlcokList[0].m_Column - 1;
                    x2 = m_MovingBlcokList[0].m_Row - 1;
                    y2 = m_MovingBlcokList[0].m_Column ;
                    x3 = m_MovingBlcokList[0].m_Row - 2;
                    y3 = m_MovingBlcokList[0].m_Column;
                    x4 = m_MovingBlcokList[0].m_Row - 1;
                    y4 = m_MovingBlcokList[0].m_Column+1;
                    if (setRotate(x1, y1, x2, y2, x3, y3, x4, y4)) {
                        m_ObjStateNow = 0;
                    }
                    break;
                }
                break;
        }
    }
    bool setRotate(int x1,int y1,int x2,int y2, int x3, int y3, int x4, int y4) {
        bool flag = false;
        if (checkRowPosRight(x1) && checkRowPosRight(x2) && checkRowPosRight(x3) && checkRowPosRight(x4) && checkColumnPosRight(y1) && checkColumnPosRight(y2) && checkRowPosRight(y3) && checkColumnPosRight(y4)) {
            MoveObj.ObjType type = MoveObj.ObjType.Init;
            type = m_MovingBlcokList[0].m_ObjType;
            if (checkPosUseable(x1,y1)&& checkPosUseable(x2, y2) && checkPosUseable(x3, y3) && checkPosUseable(x4, y4)) {
                foreach (var item in m_MovingBlcokList) {
                    item.DeLight();
                }
                m_MovingBlcokList[0] = m_AllBlockList[x1 * m_ColumnCount + y1];
                m_MovingBlcokList[1] = m_AllBlockList[x2 * m_ColumnCount + y2];
                m_MovingBlcokList[2] = m_AllBlockList[x3 * m_ColumnCount + y3];
                m_MovingBlcokList[3] = m_AllBlockList[x4 * m_ColumnCount + y4];
                foreach (var item in m_MovingBlcokList) {
                    item.HighLight(type);
                    item.m_IsMoving = true;
                }
                flag = true;
            }

        }
        return flag;
    }
    bool checkPosUseable(int a1,int a2) {
        return !m_AllBlockList[a1 * m_ColumnCount + a2].m_IsHighLight || m_AllBlockList[a1 * m_ColumnCount + a2].m_IsMoving;
    }
    bool checkRowPosRight(int a) {
        if (a >= 0 && a < m_RowCount) {
            return true;
        }
        return false;
    }
    bool checkColumnPosRight(int a) {
        if (a >= 0 && a < m_ColumnCount) {
            return true;
        }
        return false;
    }



    public bool CheckHorizenEnable(List<Block> poslist,int movecount) {
        foreach(var item in poslist) {
            int x = item.m_Row;
            int y = item.m_Column;
            if (y + movecount >= m_ColumnCount || y + movecount < 0) {
                return false;
            }
            if(m_AllBlockList[x*m_ColumnCount+ y + movecount].m_IsHighLight&& !m_AllBlockList[x * m_ColumnCount + y + movecount].m_IsMoving) {
                return false;
            }
        }
        return true;
    }
    public bool CheckVerticalEnable(List<Block> poslist, int movecount) {
        foreach (var item in poslist) {
            int x = item.m_Row;
            int y = item.m_Column;
            if (x + movecount >= m_RowCount) {
                return false;
            }
            if (m_AllBlockList[(x+movecount) * m_ColumnCount + y ].m_IsHighLight&&!m_AllBlockList[(x + movecount) * m_ColumnCount + y].m_IsMoving) {
                return false;
            }
        }
        return true;
    }
    public void ReStart() {
        SceneManager.LoadScene(0);
    }
    public void PauseGame() {
        if (!m_isStarted)
            return;
        if (m_isPaused) {
            Time.timeScale = 1f;
            m_PauseText.text = "暂停";
            m_isPaused = false;
        } else {
            Time.timeScale = 0f;
            m_PauseText.text = "继续";
            m_isPaused = true;
        }
    }
    public void StartGame() {
        if (m_isStarted) {
            ReStart();
            return;
        }
            
        m_isStarted = true;
        m_updateAction += updateFall;
        InitNewOne();
    }
}
